# /usr/bin/python3

# Author: 爱编程的章老师
# @Time: 2021/1/5 0005
# E-mail: Bluesand2010@163.com

import pygame
import sys
import time

def homeworkd():
    pygame.init()
    s = pygame.display.set_mode((800, 600))
    rect = pygame.Rect(400,300, 100,100)
    GREEN = 0, 255, 0
    BLACK = 0,0,0
    pygame.draw.rect(s, GREEN, rect)
    pygame.display.update()

    dx = 5
    while 1:
        for e in pygame.event.get():
            if e.type == pygame.QUIT:
                sys.exit()
        if dx == 5 and rect.right > 795:
                dx = -5
        elif rect.left <=0:
                dx = 5
        rect.move_ip(dx, 0)
        s.fill(BLACK)
        pygame.draw.rect(s, GREEN, rect)
        pygame.display.update()
        time.sleep(0.01)


def pong1():
    pygame.init()
    s = pygame.display.set_mode((800, 600))
    rect1 = pygame.Rect(100,300, 100,100)
    rect2 = pygame.Rect(400,300,100,100)
    GREEN = 0, 255, 0 # 绿色
    BLUE = 0, 0, 255  # 蓝色
    BLACK = 0,0,0  # 黑色
    pygame.draw.rect(s, GREEN, rect1)
    pygame.draw.rect(s, BLUE, rect2)

    pygame.display.update()

    while 1:
        for e in pygame.event.get():
            if e.type == pygame.QUIT:
                sys.exit()
        if rect2.left > rect1.right:
            print("未碰撞")
            rect2.move_ip(-5, 0)
        else:
            print("碰撞成功")
        s.fill(BLACK)
        pygame.draw.rect(s, BLUE, rect2)
        pygame.draw.rect(s, GREEN, rect1)
        pygame.display.update()
        time.sleep(0.1)

def pong2():
    pygame.init()
    s = pygame.display.set_mode((800, 600))
    rect1 = pygame.Rect(100,300, 100,100)
    rect2 = pygame.Rect(400,300,100,100)
    GREEN = 0, 255, 0 # 绿色
    BLUE = 0, 0, 255  # 蓝色
    BLACK = 0,0,0  # 黑色
    pygame.draw.rect(s, GREEN, rect1)
    pygame.draw.rect(s, BLUE, rect2)

    pygame.display.update()

    while 1:
        for e in pygame.event.get():
            if e.type == pygame.QUIT:
                sys.exit()
        if rect1.colliderect(rect2):
            print("碰撞成功")

        else:
            print("未碰撞")
            rect2.move_ip(-5, 0)
        s.fill(BLACK)
        pygame.draw.rect(s, BLUE, rect2)
        pygame.draw.rect(s, GREEN, rect1)
        pygame.display.update()
        time.sleep(0.1)

def pygame_contains():
    pygame.init()
    s = pygame.display.set_mode((800, 600))
    rect1 = pygame.Rect(100, 100, 600, 400)
    rect2 = pygame.Rect(400, 300, 100, 100)
    GREEN = 0, 255, 0  # 绿色
    BLUE = 0, 0, 255  # 蓝色
    BLACK = 0, 0, 0  # 黑色
    pygame.draw.rect(s, BLUE, rect2)
    pygame.draw.rect(s, GREEN, rect1)

    pygame.display.update()

    while 1:
        for e in pygame.event.get():
            if e.type == pygame.QUIT:
                sys.exit()
        if rect1.contains(rect2):
            print("我是无敌的")
        else:
            print("我感觉我活不久了")
        rect2.move_ip(4, 0)
        s.fill(BLACK)
        pygame.draw.rect(s, GREEN, rect1)
        pygame.draw.rect(s, BLUE, rect2)
        pygame.display.update()
        time.sleep(0.1)

if __name__ == '__main__':
    pygame_contains()